package com.fmjava.service_video.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fmjava.service_video.entity.Author;
import com.fmjava.service_video.entity.Chapter;
import com.fmjava.service_video.entity.vo.AuthorQuery;
import com.fmjava.service_video.entity.vo.ContentVo;
import com.fmjava.service_video.service.AuthorService;
import com.fmjava.utils.ResponseResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 创作者 前端控制器
 * </p>
 *
 * @author fmjava
 * @since 2021-07-01
 */
@RestController
@RequestMapping("/service_video/author")
@Api(tags = "作者组")
public class AuthorController {

    @Autowired
    AuthorService authorService;

    @ApiOperation(value = "获取所有的作者列表")
    @GetMapping("/getAuthorList")
    public ResponseResult getAuthorList(){
        List<Author> authorList =authorService.list(null);
        return ResponseResult.ok().data("list",authorList);
    }

    @ApiOperation(value = "逻辑删除作者")
    @PostMapping("/deleteAuthor/{id}")
    public ResponseResult deleteAuthor(@ApiParam(name = "id" ,value="作者id", required = true) @PathVariable String id)
    {

         authorService.removeById(id);
        return ResponseResult.ok();
    }

    @ApiOperation(value = "分页查询作者列表")
    @PostMapping("/pageList/{page}/{limit}")  //get请求无法发送json数据
    public ResponseResult pageList(@ApiParam(name = "page",value = "当前页",required = true)@PathVariable Long page,
                                   @ApiParam(name ="limit",value = "每页多少条数据",required = true)@PathVariable Long limit,
                                   @ApiParam(name = "authorQuery",value = "条件查询参数")@RequestBody(required = false) AuthorQuery authorQuery){

        Page<Author> pageInfo = new Page<>(page,limit);
        authorService.page(pageInfo, null);
        authorService.pageQuery(pageInfo,authorQuery);
        //总页数
        long total = pageInfo.getTotal();

        //每页数据
        List<Author> records = pageInfo.getRecords();
        return ResponseResult.ok().data("total",total).data("rows",records);
    }

    @ApiOperation(value = "根据id查询作者")
    @GetMapping("/getAuthorWithId/{id}")
    public ResponseResult getAuthorWithId(@ApiParam(name = "id", value = "作者id",required = true)@PathVariable String id){
        Author author = authorService.getById(id);
        return   ResponseResult.ok().data("item",author);
    }

    @ApiOperation(value = "添加作者")
    @PostMapping("/insertAuthor")
    public ResponseResult insertAuthor(@ApiParam(name = "author", value = "作者添加信息",required = true)@RequestBody Author author){
        System.out.println(author.toString());
        authorService.save(author);
        return ResponseResult.ok();
    }

    @ApiOperation(value = "更新作者信息")
    @PostMapping("/updateAuthor")
    public ResponseResult updateAuthor(@ApiParam(name = "author", value = "作者更新信息",required = true) @RequestBody Author author)
    {
        authorService.updateById(author);
        return ResponseResult.ok();
    }



    @PostMapping("/addContentInfo")
    @ApiOperation(value = "商品基本信息的存储")
    public ResponseResult addContentInfo(@ApiParam(name = "ContentVo", value = "商品基本信息",required = true)@RequestBody ContentVo contentVo){
        return ResponseResult.ok();
    }



}

